package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.HcConsumablesInfo;
import com.ruoyi.system.domain.SupRes;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IHcConsumablesInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 * 
 * @author ruoyi
 * @date 2023-03-24
 */
@RestController
@RequestMapping("/system/info")
public class HcConsumablesInfoController extends BaseController
{
    @Autowired
    private IHcConsumablesInfoService hcConsumablesInfoService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(HcConsumablesInfo hcConsumablesInfo)
    {
        startPage();
        List<HcConsumablesInfo> list = hcConsumablesInfoService.selectHcConsumablesInfoList(hcConsumablesInfo);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HcConsumablesInfo hcConsumablesInfo)
    {
        List<HcConsumablesInfo> list = hcConsumablesInfoService.selectHcConsumablesInfoList(hcConsumablesInfo);
        ExcelUtil<HcConsumablesInfo> util = new ExcelUtil<HcConsumablesInfo>(HcConsumablesInfo.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hcConsumablesInfoService.selectHcConsumablesInfoById(id));
    }

    @GetMapping("/getwarnlist")
    public AjaxResult getWarningInfo()
    {
        System.out.println(hcConsumablesInfoService.QueryWarnningInfo());
        return AjaxResult.success(hcConsumablesInfoService.QueryWarnningInfo());
    }
    @GetMapping("/gettimelist")
    public AjaxResult judge()
    {
        System.err.println(hcConsumablesInfoService.QueryTimeLimit());
        return AjaxResult.success(hcConsumablesInfoService.QueryTimeLimit());
    }

    @GetMapping("/getSupplierlist")

    public List<SupRes> getSupplierlist()
    {
        List<SupRes> map=new ArrayList<>();
        map=hcConsumablesInfoService.QuerySupplierInfo();
        for (SupRes entry : map) {
            System.out.println("Key: " + entry.getName() + ", Value: " + entry.getValue());
        }
        return map;
    }
    /**
     * 耗材信息新增
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HcConsumablesInfo hcConsumablesInfo)
    {
        return toAjax(hcConsumablesInfoService.insertHcConsumablesInfo(hcConsumablesInfo));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HcConsumablesInfo hcConsumablesInfo)
    {
        return toAjax(hcConsumablesInfoService.updateHcConsumablesInfo(hcConsumablesInfo));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hcConsumablesInfoService.deleteHcConsumablesInfoByIds(ids));
    }
}
